package cn.school.thoughtworks.section1;

import cn.school.thoughtworks.section3.PracticeA;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class PracticeB {
    List<String> collectSameElements(List<String> collection1, List<List<String>> collection2) {
        List<String> reduceCollection = flattenCollection2(collection2);
        return collection1.stream().filter(elm -> reduceCollection.contains(elm)).collect(Collectors.toList());
    }

    private List<String> flattenCollection2(List<List<String>> collection2){
        List<String> reduceCollection = new ArrayList<>();
        for (List<String> curCollection : collection2){
            reduceCollection.addAll(curCollection);
        }
        return reduceCollection;
    }
}
